<?php

namespace Admin\Models\read;

use Phalcon\Db\Column;
use Phalcon\Di;
class Comment extends BaseRead
{

    public $id;
    public $articleid;
    public $articletitle;
    public $articleurl;
    public $articletype;
    public $channelid;
    public $channelname;
    public $tagid;
    public $tagname;
    public $userid;
    public $username;
    public $usertype;
    public $schoolid;
    public $schoolname;
    public $comment;
    public $locking;
    public $teacherid;
    public $teachername;
    public $createtime;
    public $updatetime;
    public $status;
    public $star;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setConnectionService(parent::Service);
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return parent::getTableName('comment');
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return Channel[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return channel
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 批量删除并返回结果
     *
     * @param $ids
     * @return mixed
     *
     * create by ck 20170420
     */
    public static function deleteRecordById($ids)
    {
        if(!$ids) return true;
        return self::find([
            'conditions' => 'status = 1 AND id IN ({idArr:array})',
            'bind'       => ['idArr' => explode(',', $ids)],
            'bindType'   => ['idArr' => Column::BIND_PARAM_INT]
        ])->delete();
    }

}
